<template>
	<view class="wrap">
		<u-form :model="model" :rules="rules" ref="uForm">
			<u-form-item label-width="350" :label-position="labelPosition" label="原有钻井液体积 (m³)" prop="zjytj">
				<u-input :border="border" placeholder="原有钻井液体积" v-model="model.zjytj" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350" :label-position="labelPosition" label="原有钻井液密度 (g/cm³)" prop="zjymd">
				<u-input :border="border" placeholder="原有钻井液密度" v-model="model.zjymd" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350" :label-position="labelPosition" label="加水后钻井液密度 (g/cm³)" prop="jsmd">
				<u-input :border="border" placeholder="加水后钻井液密度" v-model="model.jsmd" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350" :label-position="labelPosition" label="水的密度 (g/cm³)" prop="smd">
				<u-input :border="border" placeholder="水的密度" v-model="model.smd" type="digit"></u-input>
			</u-form-item>
		</u-form>

		<u-button type="primary" @click="submit">计算</u-button>

		<view class="u-config-wrap">
			<view class="u-config-item">
				<view class="u-item-title">计算结果</view>
				<u-form-item style="font-size: 22px;" :leftIconStyle="{color: '#888', fontSize: '32rpx'}"
					label-width="300" :label-position="labelPosition" label="最大上顶力" prop="force">
					<span v-if="model.force"> {{model.force}} 立方米 </span>
				</u-form-item>
			</view>
			<view class="u-config-item">
				<view class="u-item-title">计算公式</view>
				<view class="u-item-desc">V水 = V原 *（ρ原-ρ稀）/（ρ稀-ρ水）</view>
				<view class="u-item-desc">式中：<br>
					V水—所需加水的体积，m³；<br>
					ρ原—原有钻井液的密度，g/cm³；<br>
					ρ水—水的密度，g/cm³；<br>
					ρ稀—加水后钻井液的密度，g/cm³；<br>
					V原—原有钻井液的体积，m³。</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {
					zjytj: '',
					zjymd: '',
					jsmd: '',
					smd: '',
					force: ''
				},
				rules: {
					zjytj: [{
						required: true,
						message: '请输入原有钻井液体积',
						trigger: 'blur'
					}],
					zjymd: [{
						required: true,
						message: '请输入原有钻井液密度',
						trigger: 'blur'
					}],
					jsmd: [{
						required: true,
						message: '请输入加水后钻井液密度',
						trigger: 'blur'
					}],
					smd: [{
						required: true,
						message: '请输入水的密度',
						trigger: 'blur'
					}]
				},
				labelPosition: 'left',
				border: true,

			};
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						// F = 1/4*ΠD²P * 10^(-3)
						const V = parseFloat(this.model.zjytj);
						const PY = parseFloat(this.model.zjymd);
						const PX = parseFloat(this.model.jsmd);
						const PS = parseFloat(this.model.smd);
						// V水 = V原 *（ρ原-ρ稀）/（ρ稀-ρ水）
						this.model.force = (V*(PY-PX)*(PX-PS)).toFixed(2);
					}
				});
			}
		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}

	.u-config-wrap {
		margin-top: 30rpx;
	}

	.u-config-title {
		padding: 20rpx;
		font-size: 32rpx;
		font-weight: bold;
	}

	.u-config-item {
		padding: 20rpx;
	}

	.u-item-title {
		font-size: 28rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}

	.u-item-desc {
		font-size: 24rpx;
		color: #666;
	}
</style>